public with sharing class ctlr_GeneratePerformaInvoice 
{
	
	//For Variable...
	List<Fines__c> suspensionInvoiceItemList = null;
	public Account accountObject {get;set;}
	public List<Invoice__c> invoiceObjectList {get;set;}//= new Map<string,Invoice__c>();
    //Invoice_Line_Item__c tempInvoiceItem = null;
    List<string> tempInvoiceItem = null;
    public DateTime CurrentTime {get;set;}
    //public List<Invoice_Line_Item__c> invoiceLineItemList {get;set;}//= new List<Invoice_Line_Item__c>();
	
	public List<List<string>> invoiceLineItemList {get;set;}
	string accountId = null;
	string recordTypeName = null;
	public string invoiceName {get;set;}
	public decimal invoiceTotal {get;set;}
	
	//For Constructor...
    public ctlr_GeneratePerformaInvoice() 
    {
    	//Initializing the Properties...
    	invoiceObjectList = new List<Invoice__c>();
    	//invoiceLineItemList = new List<Invoice_Line_Item__c>();
    	invoiceLineItemList = new List<List<string>>();
    	accountObject = new Account();
    	invoiceName = 'Performa Invoice';
    	invoiceTotal = 0;
    	//Initializing the Time....
    	CurrentTime = Datetime.now().addhours(4);
    	//Initializing the Parameters...
    	accountId = ApexPages.CurrentPage().getParameters().get('id');
    	recordTypeName = ApexPages.CurrentPage().getParameters().get('recordTypeName');
    	
    	System.debug('The Account Id => '+ accountId);
    	System.debug('The Record Type Name => '+ recordTypeName);
    	
    }
    
    //For Generating the Performa Invoices...
    public PageReference generatingPerformaInvoiceMethod()
    {
    	try
    	{
    		
    		//Fetching the Account...
    		accountObject = [select id,Name, LicenseNumber__r.Name from Account where id =: accountId];
    		//Create a Invoice Object....
            Invoice__c tempInvoiceObject = new Invoice__c();
            //tempInvoiceObject.Id = '13213232312323';
            tempInvoiceObject.Account__c = accountId;
            tempInvoiceObject.Date__c = System.Today();
            tempInvoiceObject.Fee_Application_Type__c = recordTypeName;
            
            //Adding in Map....
            invoiceObjectList.add(tempInvoiceObject);
            
            System.debug('The List => '+ invoiceObjectList.size());
            System.debug('The Invoice Id => '+ tempInvoiceObject.Id);
            //For Fines Object...
            suspensionInvoiceItemList = new List<Fines__c>([Select Id,Account__c,Status__c, Name,Fines_Included__c, Fine_Total_Amount_Due__c From Fines__c where Fines_Included__c = true and Status__c = 'Approved' AND Account__c =: accountId]);
            
            System.debug('The Suspension Item List ==> '+ suspensionInvoiceItemList.size());
            
            //From Suspension Invoice Items....
            if(suspensionInvoiceItemList.size() > 0)
            {
            	for(Fines__c suspensionObject : suspensionInvoiceItemList)
            	{
            		//We only neeed to put the Invoice Line Item...
                    tempInvoiceItem = new List<string>();
                    
                    tempInvoiceItem.add(string.valueof(''));
                    tempInvoiceItem.add(suspensionObject.Name);
                    tempInvoiceItem.add('');
                    tempInvoiceItem.add('');
                    tempInvoiceItem.add('');
                    tempInvoiceItem.add(string.valueof(suspensionObject.Fine_Total_Amount_Due__c));
                    invoiceTotal = invoiceTotal + suspensionObject.Fine_Total_Amount_Due__c;
                    System.debug('The Temp invoice Item List in Suspension =>' + tempInvoiceItem.size());
                    //Now Add the Invoice Item...
                	invoiceLineItemList.add(tempInvoiceItem);
                    
                    
            	}
            }
            
            if(recordTypeName == 'Company Amendment - Change Company Activity')
    		{
    			Fee__c feeObject = new Fee__c();
        		feeObject = [Select Id,Name,Price__c,Fee_Type__c,CreatedDate from Fee__c where  Fee_Type__c=: 'Amendment - Change Activity' order by CreatedDate limit 1];
    			
    			tempInvoiceItem = new List<string>();
    			
    			tempInvoiceItem.add(string.valueof(''));
    			tempInvoiceItem.add(string.valueof(feeObject.Name));
    			tempInvoiceItem.add(string.valueof(''));
                tempInvoiceItem.add(string.valueof(''));
                tempInvoiceItem.add(string.valueof(''));
                tempInvoiceItem.add(string.valueof(feeObject.Price__c));
    			
    			//Calculating the Invoice Total...
    			invoiceTotal = invoiceTotal + feeObject.Price__c;

    			System.debug('The Temp invoice Item List in Fee =>' + tempInvoiceItem.size());

                //Now Add the Invoice Item...
                invoiceLineItemList.add(tempInvoiceItem);
    			System.debug('The feeObject Item List ');
    			
    		}
    		
    		System.debug('The Invoice Item List ==> '+ invoiceLineItemList.size());
            
    		
    	}
    	catch(Exception exp)
    	{
    		System.debug('The Exception is => '+ exp.getMessage());
    		return null;
    	}
    	
    	//Return the values...
    	return null;
    	
    }
    
	
	

}